package com.bjtg.threegoclinet.service;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.SystemClock;

import com.log.LatteLogger;
import com.tencent.bugly.beta.Beta;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by 86463 on 2017/11/19.
 */

public class AutoUpdateService extends Service {
    private ExecutorService executorService = Executors.newSingleThreadExecutor();

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        LatteLogger.e("Patch", "AutoService start");
        executorService.execute(() -> {
            Beta.checkUpgrade();
        });
        AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
        int tenSencond = 30 * 1000;
        long triggerAtTime = SystemClock.elapsedRealtime() + tenSencond;
        Intent i = new Intent(this, AutoUpdateService.class);
        PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
        manager.cancel(pi);
        manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi);
        return super.onStartCommand(intent, flags, startId);
    }
}
